package com.guohe3.just.es;

import com.guohe3.just.DO.Score;
import com.guohe3.just.DO.Student;
import com.guohe3.just.mapper.ScoreMapper;
import com.guohe3.just.mapper.StudentMapper;
import com.guohe3.just.service.IScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 浦希成
 * 2019-01-15
 */
@RequestMapping("es")
@RestController
@Slf4j
public class EsController {
    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private ScoreMapper scoreMapper;

    @Autowired
    private StudentEsRepository studentEsRepository;

    @Autowired
    private ScoreEsRepository scoreEsRepository;
    @GetMapping("student")
    public Integer  synchronousStudent(){
        List<Student> students = studentMapper.selectAll();
        int i=0;
        for (Student student : students) {
            studentEsRepository.save(student);
            log.info("同步"+i+++"条数据");
        }
        return i;
    }
    @GetMapping("score")
    public Integer  synchronousSCore(){
        List<Score> scores = scoreMapper.selectAll();
        int i=0;
        for (Score score : scores) {
            scoreEsRepository.save(score);
            log.info("同步"+i+++"条数据");
        }
        return i;
    }
}
